var pageIndex = 0;
var pageSize = 12;
var pageTotal = 1;
var slotStatus = ["all", "idle", "using"];
var sIndex = 0;
$(document).ready(function () {
    search();
});
function resetPage() {
    pageIndex = 0;
}
function search(selectedIndex) {
    sIndex = selectedIndex;
    $.get(
        "/park_info/search?slotStatus=" + slotStatus[selectedIndex] + "&page=" + pageIndex + "&pageSize=" + pageSize,
        function (data, status) {
            pageTotal = data[data.length - 1] - 1;
            if (pageTotal < 0) pageTotal = 0;
            $("#parking").empty();
            for (var i=0;i<data.length - 1;i++) {
                $("#parking").append(insertTableRow(data[i]));
            }
            $("#info-showpage").html("当前第" + (pageIndex + 1) + " 页，共 " + (pageTotal + 1) + " 页");
        }
    );
}
function miss(e) {
    switch (e.innerHTML) {
        case "首页":
            pageIndex = 0;
            search(sIndex);
            break;
        case "上一页":
            if (pageIndex > 0) {
                pageIndex--;
                search(sIndex);
            }
            break;
        case "下一页":
            if (pageIndex < pageTotal) {
                pageIndex++;
                search(sIndex);
            }
            break;
        case "尾页":
            pageIndex = pageTotal;
            search(sIndex);
            break;
    }
}
function insertTableRow(data) {
    return "<div class='tabs book clearfix'>\n" +
                "<dl>\n" +
                    "<dt>\n" +
                        "<a><img src='../static/images/" + (data.idle ? "cw" : "cw2") + ".png' alt='" + (data.idle ? "空闲" : data.parkCarId) + "' title='" + (data.idle ? "空闲" : data.parkCarId) + "' style='cursor: pointer;'/></a>\n" +
                    "</dt>\n" +
                    "<dd>\n" +
                        "<p>车位" + data.id + "</p>\n" +
                        "<p style=\"color: blue;\">" + (data.idle ? "空闲" : data.parkCarId) + "</p>\n" +
                    "</dd>\n" +
                "</dl>\n" +
            "</div>";
}